package pl.matt.media.manager.impl;

import java.util.Collection;

import pl.matt.media.manager.ObjectsDetectorManager;
import pl.matt.media.model.wrapper.OpenCVRegionsWrapper;
import pl.matt.opencv.OpenCVDetection;

/**
 * @author mateusz
 *
 */
public class ObjectsDetectorManagerImpl implements ObjectsDetectorManager {

	/**
	 * plik w katalogu resources/cascades/
	 */
	private String faceHaarCascade = "haarcascade_frontalface_default.xml";
	private int faceScanWindowSize = 100;

	/**
	 * plik w katalogu resources/cascades/
	 */
	private String leftEyeHaarCascade = "ojoD.xml";
	private String rightEyeHaarCascade = "ojoI.xml";
	//private String eyesHaarCascade = "haarcascade_eye_new.xml";
	private int eyeScanWindowSize = 25;
	
	/**
	 * plik w katalogu resources/cascades/
	 */
	private String nosesHaarCascade = "haarcascade_nose2.xml";
	private int noseScanWindowSize = 25;
	
	/**
	 * plik w katalogu resources/cascades/
	 */
	private String mouthHaarCascade = "haarcascade_mouth.xml";
	private int mouthScanWindowSize = 25;		
	
	/* (non-Javadoc)
	 * @see pl.matt.media.manager.impl.ObjectsDetectorManager#detectFaces(java.lang.String)
	 */
	@Override
	public Collection<pl.matt.model.Rectangle> detectFaces(String filePath) {
		return detectRegions(filePath, faceHaarCascade, faceScanWindowSize);
	}

	@Override
	public Collection<pl.matt.model.Rectangle> detectLeftEyes(String filePath) {
		return detectRegions(filePath, leftEyeHaarCascade, eyeScanWindowSize);
	}
	
	@Override
	public Collection<pl.matt.model.Rectangle> detectRightEyes(String filePath) {
		return detectRegions(filePath, rightEyeHaarCascade, eyeScanWindowSize);
	}

	@Override
	public Collection<pl.matt.model.Rectangle> detectNoses(String filePath) {
		return detectRegions(filePath, nosesHaarCascade, noseScanWindowSize);
	}
	
	@Override
	public Collection<pl.matt.model.Rectangle> detectMouths(String filePath) {
		return detectRegions(filePath, mouthHaarCascade, mouthScanWindowSize);
	}
	
	private Collection<pl.matt.model.Rectangle> detectRegions(String filePath, String cascade, int windowSize) {
		OpenCVDetection detection = new OpenCVDetection(cascade);
		OpenCVRegionsWrapper regionsWrapper = new OpenCVRegionsWrapper(detection.detectObject(filePath, windowSize));
		return regionsWrapper.toRectangleCollection();
	}
	
	public void setFaceHaarCascade(String faceHaarCascade) {
		this.faceHaarCascade = faceHaarCascade;
	}

	public void setFaceScanWindowSize(int faceScanWindowSize) {
		this.faceScanWindowSize = faceScanWindowSize;
	}
	
}
